
package web.util;

import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;

public class LifeCycleListener implements PhaseListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1958899585914749735L;

	public LifeCycleListener() {
		System.out
				.println("LIFE_CYCLE_LISTENER: Construindo a classe LifeCycleListener");
	}

	@Override
	protected void finalize() throws Throwable {
		System.out
				.println("LIFE_CYCLE_LISTENER: Destroindo a classe LifeCycleListener");
		super.finalize();
	}

	@Override
	public PhaseId getPhaseId() {
		return PhaseId.ANY_PHASE;
	}

	@Override
	public void beforePhase(PhaseEvent event) {
		if (event.getPhaseId().equals(PhaseId.RESTORE_VIEW)){
			System.out.println("<< INICIOU LIFECYCLE DO JSF >>");
		}
		System.out.println("<"
				+ event.getPhaseId() +">");
	}

	@Override
	public void afterPhase(PhaseEvent event) {
		System.out.println("</"
				+ event.getPhaseId() +">");
		
		if (event.getPhaseId().equals(PhaseId.RENDER_RESPONSE)){
			System.out.println("<< FINALIZOU LIFECYCLE DO JSF >>\n\n");
		}
		
	}

}
